package com.xqboss.apps.service.user;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xqboss.apps.domain.user.SysUserWalletWithdrawHandler;
import com.xqboss.apps.enums.user.WithdrawStatusEnum;
import com.xqboss.apps.mapper.user.SysUserWalletWithdrawHandlerMapper;
import com.xqboss.common.core.domain.model.LoginUser;
import com.xqboss.common.exception.ServiceException;
import com.xqboss.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *     用户钱包提现处理
 * </p>
 * @author Trent
 * @date 2023/8/15
 */
@Service
public class SysUserWalletWithdrawHandlerService extends ServiceImpl<SysUserWalletWithdrawHandlerMapper, SysUserWalletWithdrawHandler> {

    @Autowired
    private SysUserWalletWithdrawService userWalletWithdrawService;

    /**
     * 提现处理
     */
    public void addRecord(Long withdrawId, WithdrawStatusEnum status, String opinion){
        SysUserWalletWithdrawHandler handler = new SysUserWalletWithdrawHandler();
        handler.setWithdrawId(withdrawId);
        handler.setOpinion(opinion);
        handler.setStatus(status);
        LoginUser loginUser = SecurityUtils.getLoginUser();
        handler.setHandlerUserId(loginUser.getUserId());
        handler.setHandlerUserName(loginUser.getNickName());
        // 新增处理记录
        boolean save = save(handler);
        if(!save){
            throw new ServiceException("操作失败！");
        }
    }

    /**
     * 获取提现的提现记录
     *
     * @return
     */
    public List<SysUserWalletWithdrawHandler> getWithdrawHandlerList(Long withdrawId){
        return list(new LambdaQueryWrapper<SysUserWalletWithdrawHandler>()
                .eq(SysUserWalletWithdrawHandler::getWithdrawId, withdrawId)
                .orderByAsc(SysUserWalletWithdrawHandler::getId));
    }
}
